package cup.common.common;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @author : ruoyu
 * @date : 2022/6/30
 */
public class MyBaseEntity implements Serializable {

	@JsonSerialize(
		using = ToStringSerializer.class
	)
	@ApiModelProperty("主键id")
	@TableId(
		value = "id",
		type = IdType.ASSIGN_ID
	)
	private Long id;
	@JsonSerialize(
		using = ToStringSerializer.class
	)
	@ApiModelProperty("创建人")
	@TableField(
		fill = FieldFill.INSERT
	)
	private Long createUser;
	@DateTimeFormat(
		pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@JsonFormat(
		pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@ApiModelProperty("创建时间")
	@TableField(
		fill = FieldFill.INSERT
	)
	private Date createTime;
	@JsonSerialize(
		using = ToStringSerializer.class
	)
	@ApiModelProperty("更新人")
	@TableField(
		fill = FieldFill.INSERT_UPDATE
	)
	private Long updateUser;
	@DateTimeFormat(
		pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@JsonFormat(
		pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@ApiModelProperty("更新时间")
	@TableField(
		fill = FieldFill.INSERT_UPDATE
	)
	private Date updateTime;
	@ApiModelProperty("业务状态")
	private Integer status;
	@TableLogic
	@ApiModelProperty("是否已删除")
	private Integer isDeleted;

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}

		if (o == null || getClass() != o.getClass()) {
			return false;
		}

		MyBaseEntity that = (MyBaseEntity) o;

		return new EqualsBuilder().append(id, that.id).append(createUser, that.createUser).append(createTime, that.createTime).append(updateUser, that.updateUser).append(updateTime, that.updateTime).append(status, that.status).append(isDeleted, that.isDeleted).isEquals();
	}

	@Override
	public String toString() {
		return "MyBaseEntity{" +
			"id=" + id +
			", createUser=" + createUser +
			", createTime=" + createTime +
			", updateUser=" + updateUser +
			", updateTime=" + updateTime +
			", status=" + status +
			", isDeleted=" + isDeleted +
			'}';
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(id).append(createUser).append(createTime).append(updateUser).append(updateTime).append(status).append(isDeleted).toHashCode();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCreateUser() {
		return createUser;
	}

	public void setCreateUser(Long createUser) {
		this.createUser = createUser;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Long getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(Long updateUser) {
		this.updateUser = updateUser;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(Integer isDeleted) {
		this.isDeleted = isDeleted;
	}

	public MyBaseEntity() {
	}

	public MyBaseEntity(Long id, Long createUser, Date createTime, Long updateUser, Date updateTime, Integer status, Integer isDeleted) {
		this.id = id;
		this.createUser = createUser;
		this.createTime = createTime;
		this.updateUser = updateUser;
		this.updateTime = updateTime;
		this.status = status;
		this.isDeleted = isDeleted;
	}
}
